package ssm.scheduledJob;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import ssm.dao.TrackPerception;
import ssm.model.TrackMapper;
import ssm.model.TrackPerceptionMapper;
import ssm.utils.TimeUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class Perception {
    @Value("${morning_start}")
    public String morning_start;
    @Value("${morning_end}")
    private String morning_end;
    @Value("${afternoon_start}")
    private String afternoon_start;
    @Value("${afternoon_end}")
    private String afternoon_end;
    @Value("${evenoon_start}")
    private String evenoon_start;
    @Value("${evenoon_end}")
    private String evenoon_end;
    @Value("${midnight_start}")
    private String midnight_start;
    @Value("${midnight_end}")
    private String midnight_end;


    @Autowired
    private TrackMapper trackMapper;
    @Autowired
    private TrackPerceptionMapper trackPerceptionMapper;


    //更新当天感知人员数据
    public void updatePerceptionByToday(){
        String today= TimeUtils.getToday();
        trackPerceptionMapper.deleteByDate(today);
        updatePerceptionByDate(today);
    }

    //更新多天感知人员数据
    public void updatePerceptionByList(String startDate,String endDate){
        List<String> dates=TimeUtils.getListDate(startDate,endDate);
        trackPerceptionMapper.deleteByList(startDate,endDate);
        for(String date:dates){
            updatePerceptionByDate(date);
        }
    }

    //单天加入
    public void updatePerceptionByDate(String date){
        Map<String,Object>param=this.workTime(date);
        List<TrackPerception> percets=trackMapper.getPerception(param);
        System.out.println("断点测试:percets》》》》》"+percets);
        for(TrackPerception perception:percets){
            trackPerceptionMapper.insert(perception);
        }
    }


    public Map<String,Object> workTime(String date){
        Map<String,Object>param=new HashMap<String, Object>();
        param.put("morning_start",date+" "+morning_start);
        param.put("morning_end",date+" "+morning_end);
        param.put("afternoon_start",date+" "+afternoon_start);
        param.put("afternoon_end",date+" "+afternoon_end);
        param.put("evenoon_start",date+" "+evenoon_start);
        param.put("evenoon_end",date+" "+evenoon_end);
        param.put("midnight_start",date+" "+midnight_start);
        param.put("midnight_end",date+" "+midnight_end);
        return param;
    }

    //
}
